prepare-root: Fix ostree= kernel argument at end
authorColin Walters <walters@verbum.org>
Sun, 1 Sep 2013 08:16:52 +0000 (04:16 -0400)
committerColin Walters <walters@verbum.org>
Mon, 2 Sep 2013 17:27:41 +0000 (13:27 -0400)
Extracting the code for parse_ostree_cmdline() and running it on some
test input (on RHEL6.4 glibc), I can reproduce the odd behavior from
getline() where it apparently returns the size of the default malloc
buffer in the size output, and some non-zero value.

This behavior would be OK except that it breaks the logic for
stripping off the trailing newline, which in turn breaks booting
because we return "ostree=foo\n".

This has worked so far in gnome-ostree because syslinux apparently
injects initrd=/path/to/initrd as a final kernel argment.

Anyways, we don't handle NUL characters here in /proc/cmdline, so
let's just call strlen () to be safe.

https://bugzilla.gnome.org/show_bug.cgi?id=707192

src/switchroot/ostree-prepare-root.c

index a77da7c64d79fdf6a91671e001b63f2f34e42ef9..25ac66b4b12d47421040c969000933e851935fbe 100644 (file)
@@ -54,8 +54,15 @@ parse_ostree_cmdline (void)
 
   if (!f)
     return NULL;
+  /* Note that /proc/cmdline will not end in a newline, so getline
+   * will fail unelss we provide a length.
+   */
   if (getline (&cmdline, &len, f) < 0)
     return NULL;
+  /* ... but the length will be the size of the malloc buffer, not
+   * strlen().  Fix that.
+   */
+  len = strlen (cmdline);
 
   if (cmdline[len-1] == '\n')
     cmdline[len-1] = '\0';